﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

namespace DALL.SysManage
{
    public class T_PUB_OPERATION
    {
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.SysManage.T_PUB_OPERATION model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_PUB_OPERATION(");
            strSql.Append("USER_ID,ACTION,TIME)");

            strSql.Append(" values (");
            strSql.Append("@USER_ID,@ACTION,@TIME)");
            strSql.Append(";select @@IDENTITY");
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "USER_ID", DbType.Int32, model.USER_ID);
            db.AddInParameter(dbCommand, "ACTION", DbType.String, model.ACTION);
            db.AddInParameter(dbCommand, "TIME", DbType.DateTime, model.TIME);
            int result;
            object obj = db.ExecuteScalar(dbCommand);
            if (!int.TryParse(obj.ToString(), out result))
            {
                return 0;
            }
            return result;
        }
    }
}
